package ModelLayer;

import java.util.ArrayList;

/**
 * Write a description of class DVDContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVDContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<DVD> dvd;
    private static DVDContainer instance;
    
    private DVDContainer()
    {
        dvd = new ArrayList<DVD>();
    }
    
    public static DVDContainer getInstance()
    {
        if(instance == null)
        {
            instance = new DVDContainer();
        }
        return instance;
    }
    
    public void addDVD(DVD d)
    {
        dvd.add(d);
    }
    
    public boolean deleteDVD(int id)
    {
        int index = 0;
        DVD d = null;
        boolean found = false;
        
        while(index < dvd.size() && !found)
        {
            d = dvd.get(index);
            
            if(d.getID() == id)
            {
                dvd.remove(index);
                found = true;
            }
            else
            {
                index++;
            }
        }
        
        return found;
    }
    
    public DVD getID(int id)
    {
        int index = 0;
        DVD d = null;
        boolean found = false;
        
        while(index < dvd.size() && !found)
        {
            d = dvd.get(index);
            
            if(d.getID() == id)
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        
        if(found)
        {
            return dvd.get(index);
        }
        else
        {
            return null;
        }
    }
    
    public ArrayList getArrayList()
    {
        return dvd;
    }
    
    public ArrayList getCopyArrayList()
    {
        for(DVD d : dvd)
        {
            return d.getArrayList();
        }
        return null;
    }
    
    public DVD getDVDIndex(int index)
    {
        return dvd.get(index);
    }
}
